package quizman.domain;
import java.util.List;

public class MultipleChoiceQuestion extends Question {
	private List <Choice> choices;
	
	public MultipleChoiceQuestion(String name)
	{
		super(name);		
	}
	
	public MultipleChoiceQuestion(String name, String text)
	{
		super(name,text);		
	}
	
	/**
	 * @param choices the choices to set
	 */
	public void setChoices(List <Choice> choices) {
		this.choices = choices;
	}

	/**
	 * @return the choices
	 */
	public List <Choice> getChoices() {
		return choices;
	}
	public String getFormHtml()
	{
		StringBuffer sb = new StringBuffer();
		String correct=null;
		for(int i=0;i != choices.size();++i)
		{
			sb.append(choices.get(i).getFormHtml(getName(), i+1));
			if(choices.get(i).isCorrect())
				correct="\n<br>\n<p>The correct answer is ("+(i+1)+").</p>\n";
		}
		sb.append(correct);
		return sb.toString();
	}
	
	public String getEditFormHtml()
	{
		StringBuffer sb = new StringBuffer();
		for(int i=0;i != choices.size();++i)
		{
			sb.append(choices.get(i).getEditFormHtml(getName(), i+1));
		}
		return sb.toString();
	}
	
}
